<?php
namespace App\Services\version;
use App\Dao\version\VersionDao;

use App\Services\BaseServices;
use Hlcreation\Basic\Helper;
use App\Exceptions\ApiException as HOException;
use App\Dao\system\SystemAdminDao;
use App\Services\system\SystemLogServices;
use Illuminate\Support\Facades\DB;

class VersionServices extends BaseServices
{
    public function __construct(VersionDao $dao)
    {
        $this->dao = $dao;
    }

    //添加版本
    public function versionSave($arr){
        try{
            DB::transaction(function () use ($arr) {
              //  if (!$this->dao->create($arr)) throw new \Exception('版本新增失败');
                $add_id = $this->dao->create($arr);
                $synchron = $this->dao->synchronizationAdd(['title'=>$arr['title'],'content'=>$arr['content'],'version'=>$arr['version'],'type'=>$arr['type'],'version_id'=>$add_id]);
                //插入日志
                $LogServices = app()->make(SystemLogServices::class);
                $LogServices->SaveLog($arr['creator_uid'],'添加版本','版本标题:'.$arr['title']);
            }, 5);
        }catch (\Exception $e){
            throw new HOException($e->getMessage());
        }

        return  true;




    }


    public function versionUpdate($id,$arr){
        return $this->dao->update(['id'=>$id['id']],$arr);
    }


    public function versionInfo($id){

        if (empty($id)) throw new HOException("版本ID不能为空、必须传递!");

        return $this->dao->getOne(['id'=>$id]);

    }


    //版本列表
    public function getList($where){
        if (empty($where['type'])) throw new HOException("版本类型不能为空、必须传递!");
        return $this->dao->versionList($where);
    }


    public function versionDelete($id){
        if (empty($id)) throw new HOException("版本ID不能为空、必须传递!");
        return $this->dao->delete(['id'=>$id]);
    }







}
